import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
from tensorflow.examples.tutorials.mnist import mnist
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
x = tf.placeholder("float",[None,784])
W = tf.Variable(tf.zeros([784,10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x,W)+b)
y_ = tf.placeholder("float", [None,10])

#cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_*tf.log(y),axis=1))
cross_entropy = -tf.reduce_sum(y_*tf.log(y),axis=1)
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
print("==================================")
print("x :",x)
print("==================================")
init = tf.initialize_all_variables()
print("==================================")
print("x :",x)
print("==================================")
sess = tf.Session()
sess.run(init)
print("cross_entropy :",cross_entropy)    
for i in range(1000):
    batch_xs, batch_ys = mnist.train.next_batch(100)
#    if (i % 100 == 0):
#        sss = sess.run(tf.matmul(x,W)+b,feed_dict={x: batch_xs,y_:batch_ys})
#        print("lksjflksdjf  :",sss)
    sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})

correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
#for i in range(len(mnist.test.images)):
#    print("i  :",i)
#    print("type : ",type(mnist.test.images))
#    print("",sess.run(accuracy, feed_dict={x: mnist.test.images[i][i], y_: mnist.test.labels[i][i]}))
print("",sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))
